
package com.scs.application.modules.upms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.mvc.controller.ImAndExAbleController;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.upms.entity.OauthClientDetails;
import com.scs.application.modules.upms.request.OauthClientDetailsQueryRequest;
import com.scs.application.modules.upms.service.OauthClientDetailsService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* 客户端 controller
*
*/
@AllArgsConstructor
@RestController
@RequestMapping("/upms/oauth_client_detailss")
public class OauthClientDetailsController  extends CrudController<OauthClientDetails,String, OauthClientDetailsService> implements ImAndExAbleController<OauthClientDetailsQueryRequest> {


    @Override
    @PostMapping
    public CommonResult add(@RequestBody @Valid OauthClientDetails entity) {
        entity.setAdditionalInformation(StringUtils.defaultString(entity.getAdditionalInformation(),"{}"));
        boolean bSave = service.saveCascadeById(entity);
        return bSave ? CommonResult.ok("新增成功", entity) : CommonResult.error("新增失败");
    }

    @Override
    @PutMapping
    public CommonResult update(@RequestBody @Valid OauthClientDetails entity) {
        entity.setAdditionalInformation(StringUtils.defaultString(entity.getAdditionalInformation(),"{}"));
        boolean bUpdate = service.updateCascadeById(entity);
        return bUpdate ? CommonResult.ok("保存成功", entity) : CommonResult.error("保存失败");
    }

    @GetMapping("/page")
    public PageResult page(OauthClientDetailsQueryRequest request) {
        IPage page = service.page(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }

    @GetMapping("/list")
    public CommonResult list(OauthClientDetailsQueryRequest request) {
        List<OauthClientDetails> list = service.list(request);
        return CommonResult.ok("查询成功", list);
    }



}
